﻿using System;
using HigLabo.Net.Extensions;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class Event: ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public String ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String CalendarID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public IdName From { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? StartTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? EndTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String location { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean IsAllDayEvent { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean IsRecurrent { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Recurrence { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 ReminderTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public AvailabilityStatus Availability { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public VisibilityStatus Visibility { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? CreatedTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? UpdatedTime { get; set; }

       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsontext"></param>
        public Event(String jsontext)
        {
            this.SetProperty(jsontext);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsontext"></param>
        public override void SetProperty(String jsontext)
        {
            var d = this.SetData(jsontext);
            this.ID = d.ToString("id");
            this.Name = d.ToString("name");
            this.Description = d.ToString("description");
            this.CalendarID = d.ToString();
            if (d.ContainsKey("from"))
            {
                this.From = new IdName(d.ToString("from"));
            }
            this.StartTime = d.ToDateTimeOffset("start_time");
            this.EndTime = d.ToDateTimeOffset("end_time");
            this.location = d.ToString("location");
            this.IsAllDayEvent = d.ToBoolean("is_all_day_event") ?? false;
            this.IsRecurrent = d.ToBoolean("is_recurrent") ?? false;
            this.Recurrence = d.ToString("recurrence");
            this.ReminderTime = d.ToInt32("reminder_time") ?? 0;
            if (d.ContainsKey("availability"))
                this.Availability = (AvailabilityStatus)Enum.Parse(typeof(AvailabilityStatus), d.ToString("availability"), true);
            if (d.ContainsKey("visibility"))
                this.Visibility = (VisibilityStatus)Enum.Parse(typeof(VisibilityStatus), d.ToString("visibility"), true);
            this.CreatedTime = d.ToDateTimeOffset("created_time");
            this.UpdatedTime = d.ToDateTimeOffset("updated_time");
        }
    }
}
 